
package com.mybatis.generator;

import com.mybatis.generator.core.Context;
import com.mybatis.generator.core.FreemarkerUtils;
import com.mybatis.generator.core.JavaBeanUtils;
import com.mybatis.generator.core.Table;


public class ServiceGenerator {

	private static final String TEMPLATE_SERVICE = "freemaker-service";
	
	private static final String TEMPLATE_SERVICE_IMPL = "freemaker-service-impl";

	public static void process(Context ctx, Table table) throws Exception {
		StringBuilder sb = new StringBuilder(ctx.getMapper());
		sb.append(JavaBeanUtils.splitString(table.getPackageName()));
		sb.append("/service/");
		String service = sb.toString() + "I" + table.getServiceName() + ".java";
		FreemarkerUtils.write(service,
				FreemarkerUtils.process(TEMPLATE_SERVICE, table));
		
		sb.append("impl/");
		sb.append(table.getServiceName()).append("Impl.java");
		FreemarkerUtils.write(sb.toString(),
				FreemarkerUtils.process(TEMPLATE_SERVICE_IMPL, table));
	}
	
}
